﻿<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" />
<html>
<head>

<title>Lynxmotion SSC32 Service Sample</title>

<meta name="Author" content="Chuck Kim (a-chuckk)" />
<meta name="Description" content="Lynxmotion SSC-32 Service" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Modified Nov-2007 by Trevor Taylor -->

<!--
<link href="../../../Common/StyleSheets/ie4.css" type="text/css" rel="Stylesheet" />
-->
<style type="text/css">
 /* Font Definitions */
 @font-face
	{font-family:Verdana;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:Verdana, Arial, sans-serif;}
h1
	{margin-right:0in;
	margin-left:0in;
	font-size:24.0pt;
	font-family:Verdana, Arial, sans-serif;
	font-weight:bold;}
h2
	{margin-right:0in;
	margin-left:0in;
	font-size:18.0pt;
	font-family:Verdana, Arial, sans-serif;
	font-weight:bold;}
li
	{font-family:Verdana, Arial, sans-serif;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
	{margin-right:0in;
	margin-left:0in;
	font-size:12.0pt;
	font-family:Verdana, Arial, sans-serif;}
p
	{margin-right:0in;
	margin-left:0in;
	font-size:12.0pt;
	font-family:Verdana, Arial, sans-serif;}
pre
	{margin-top:0in;
	margin-right:30.6pt;
	margin-bottom:0in;
	margin-left:30.6pt;
	margin-bottom:.0001pt;
	background:#D6D6A0;
	font-size:11.0pt;
	font-family:"Courier New";}
span.sdk
	{font-style:italic;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}

.TCH { font-family: Arial Black; font-size: 12pt; background-color: #b3b3b3; }
.TX { font-family: Arial; font-size: 12pt; background-color: #e6e6e6; }
</style>
</head>

<!-- Last Revision: 2006.10.17 by: a-chuckk -->
<!-- MRI Build Target: ..\src\Samples\Platforms\Lynxmotion\SSC32\Readme.html -->

<body><a name="top" />

<h1>Lynxmotion SSC-32 Service Sample</h1>

<p>
The SSC32 service is a Decentralized System Service (DSS) that communicates with a Lynxmotion SSC-32 Servo Controller over a serial port connection. The service can send commands to and receive data from the controller.
</p>
<p><em>This service was modified in Nov-2007 by Trevor Taylor, Software Technology, Australia.</em></p>

<h2>This sample shows you how to:</h2>

<ul>
   <li>
      <a href="#1-StartSample">Start and Run the Sample</a>
   </li>
   <li>
      <a href="#2-Inspect">Inspect the Service</a>
   </li>
   <li>
      <a href="#3-Partner">Partner With the Service</a>
   </li>
</ul>

<h2>Hardware and Software Prerequisites</h2>

<ul>
   <li>
      A Lynxmotion SSC-32 Servo Controller with the SSC-32 Firmware Loaded
   </li>
   <li>
      A serial port (currently <code><strong>COM1</strong></code>)
   </li>
</ul>

<p>
You will also need Microsoft Internet Explorer or another conventional web browser.

</p>

<hr />

<a href="#top"><img src="images/top.gif" border="0" alt="Top of Page" /></a>
<a href="#top" title="Top of Page">Top of Page</a>


<a name="1-StartSample" /><h2>Start and Run the Sample</h2>

<p>
Start the <strong>Microsoft Robotics Studio Command Prompt</strong> from the <strong>Start</strong>&nbsp;>&nbsp;<strong>Programs</strong> menu.
</p>

<p>
Plug the SSC-32 Servo Controller into the serial port.
</p>

<p>
Start a DssHost node and create an instance of the service by typing the following command into the Microsoft Robotics Studio Command Prompt window:
</p>

<pre><strong>dsshost /p:50000 /m:"ProMRDS/Config/Lynxmotion.SSC32.manifest.xml"</strong></pre>

<p>
This starts the service and you get a response like the following:
</p>

<pre>Initializing Dss Node with manifest file: .../ProMRDS/Config/Lynxmotion.SSC32.manifest.xml </pre>

<p>
At start up, the service automatically sends a positioning command to the controller, initializing all the servos to pulse widths of 1500 microseconds.
</p>
<p>
<b>IMPORTANT NOTE:</b> For use with the Lynx 6 Arm, the position of servo 2 is set to 1722 instead
of 1500. This makes the upper arm start out at right-angles to the lower arm.
</p>


<hr />

<a href="#top"><img src="images/top.gif" border="0" alt="Top of Page" /></a>
<a href="#top" title="Top of Page">Top of Page</a>


<a name="2-Inspect" /><h2>Inspect the Service</h2>

<p>
Start Internet Explorer (IE) and type the <strong>Service URI</strong> specified in your command prompt. For example:
</p>

<pre><strong>http://localhost:50000/ssc32</strong></pre>

<p>
This displays the SSC32 service running on your node. You will see the current pulse widths of the servo channels 0 through 31 on a web form.
</p>

<p align="center">
<img src="images/SSC32_State.jpg" border="0" alt="" />
</p>

<hr />

<a href="#top"><img src="images/top.gif" border="0" alt="Top of Page" /></a>
<a href="#top" title="Top of Page">Top of Page</a>

<a name="3-Partner" /><h2>Partner With the Service</h2>

<p><b>NOTE:</b>You probably will not need to use this service directly.
The <a href="Lynx6Arm.htm">Lynx6Arm service</a> does all the work for you.</p>

<p>
Following the steps in Service Tutorial 5, you will need to add a reference to
<code><strong>SSC32.Y2007.M01.Proxy.dll</strong></code>,
add a partner attribute to the <code><strong>SSC32</strong></code> service,
and create an operations port to <code><strong>SSC32Operations</strong></code>.
</p>

<p>
Once you have created the SSC32 operations port, you can send commands to the controller using the
<code><strong>SendSSC32Command</strong></code> operation.
Currently the SSC32 service supports two commands:
<code><strong>SSC32QueryPulseWidth</strong></code> and <code><strong>SSC32ServoMove</strong></code>.
These commands correspond to the <code><strong>Query Pulse Width</strong></code> and
<nobr><code><strong>Servo Move</strong></code></nobr> commands supported by the SSC-32 Firmware.
To add more supported commands to the service, refer to the User Manual for the SSC-32 Firmware for the command formats.
</p>

<p>
The <a href="Lynx6Arm.htm">Lynx6Arm service</a> (which can be found in the <code><strong>Lynxmotion/Lynx6Arm</strong></code> directory) provides an example of how to send messages to the SSC32 service.
In the code snippet below from <code>Lynx6Arm.cs</code>, we create a new <code><strong>SSC32QueryPulseWidth</strong></code> command for the servos we want to query:
channels <code><strong>0</strong></code> through <code><strong>5</strong></code>. Then we post the message to the operations port.
When we receive a <code><strong>SSC32PulseWidthResponse</strong></code>, we update the state of the Lynx6Arm using the
pulse widths that we received from the SSC32 service.
</p>

<p>
<pre>    <font color="green">//Create new query pulse width command</font>
    <font color="blue">int</font>[] channels = <font color="blue">new int</font>[<font color="teal">Lynx6ArmState</font>.NUM_JOINTS] { 0, 1, 2, 3, 4, 5 };
    ssc32.<font color="teal">SSC32QueryPulseWidth</font> queryCommand = <font color="blue">new</font> ssc32.<font color="teal">SSC32QueryPulseWidth</font>();
    queryCommand.Channels = channels;
    ssc32.<font color="teal">SendSSC32Command</font> command = <font color="blue">new</font> ssc32.<font color="teal">SendSSC32Command</font>(queryCommand);
    _ssc32Port.Post(command);
 
    <font color="green">//Update the arm state based on the query response</font>
    Activate(<font color="teal">Arbiter</font>.Choice(command.ResponsePort,
        <font color="blue">delegate</font>(ssc32.SSC32ResponseType response)
        {
            ssc32.<font color="teal">SSC32PulseWidthResponse</font> queryResponse = (ssc32.<font color="teal">SSC32PulseWidthResponse</font>)response;
            <font color="blue">for</font> (<font color="blue">int</font> i = 0; i &lt; 5; i++)
            {
                _state.Joints[i].State.Angular.DriveTargetOrientation = 
                    AngleToOrientationQuaternion(PulseWidthToAngle(queryResponse.PulseWidths[i]));
            }
            _state.GripperAngle = PulseWidthToAngle(queryResponse.PulseWidths[5]);
            resultPort.Post(<strong>new</strong> <font color="teal">SuccessResult</font>());
        },
        <font color="blue">delegate</font>(<font color="teal">Fault</font> fault)
        {
            resultPort.Post(<strong>new</strong> <font color="teal">Exception</font>(fault.Reason[0].ToString()));
        }
        ));</pre>
</p>

<hr />

<a href="#top"><img src="images/top.gif" border="0" alt="Top of Page" /></a>
<a href="#top" title="Top of Page">Top of Page</a>

<h2>Summary</h2>

<p>
In this sample, you were shown how to:
</p>

<ul>
   <li>
      <a href="#1-StartSample">Start and Run the Sample</a>
   </li>
   <li>
      <a href="#2-Inspect">Inspect the Service</a>
   </li>
   <li>
      <a href="#3-Partner">Partner With the Service</a>
   </li>
</ul>

<a href="#top"><img src="images/top.gif" border="0" alt="Top of Page" /></a>
<a href="#top" title="Top of Page">Top of Page</a>

<hr />

</body>
</html>
